package com.dao;/**
 * @AUTHOR: 我是章璐锋憨憨
 * @Data:
 * @Version:
 */

import com.pojo.Provider;
import com.utils.DSUtil;

import java.util.List;

/**
 * @outhor RD
 * 2021/12/24
 */
public class ProviderDao {
    public List<Provider> queryAll() {
        return DSUtil.query("select * from provider", Provider.class);
    }

    public boolean addOne(Provider provider) {
        return DSUtil.execute("insert into provider values(null,?,?,?,?,?,?,?,?)", provider.getProCode(), provider.getProName(),
                provider.getProContact(), provider.getProPhone(), provider.getProAddress(),
                provider.getProFax(), provider.getProDesc(), provider.getCreationDate()) > 0;
    }

    public List<Provider> queryById(Integer id) {
        return DSUtil.query("select * from provider where id = ?", Provider.class, id);
    }

    public void deleteById(Integer id) {
        DSUtil.execute("delete from provider where id = ?", id);
    }

    public boolean update(Integer id, Provider pro) {
        return DSUtil.execute("update provider set proCode = ?,proName = ?,proContact= ? ,proPhone = ? , proAddress = ? , " +
                        "proFax = ?, proDesc = ? where id = ?", pro.getProCode(), pro.getProName(), pro.getProContact(), pro.getProPhone(),
                pro.getProAddress(), pro.getProFax(), pro.getProDesc(), id) > 0;
    }

    public List<Provider> queryLikeCode(String proCode) {
        proCode = "%" + proCode + "%";
        return DSUtil.query("select * from provider where proCode like ?", Provider.class, proCode);
    }

    public List<Provider> queryLikeName(String proName) {
        proName = "%" + proName + "%";
        return DSUtil.query("select * from provider where proName like ?", Provider.class, proName);
    }

    public List<Provider> queryLike(String proCode, String proName) {
        proCode = "%" + proCode + "%";
        proName = "%" + proName + "%";
        return DSUtil.query("select * from provider where proCode like ? and proName like ? ", Provider.class, proCode, proName);
    }

    public List<Provider> queryLimit(Integer currentPageNo, Integer pageSize) {
        return DSUtil.query("select * from provider limit ?,?", Provider.class, (currentPageNo - 1) * pageSize, pageSize);
    }
}
